package com.fhz.loginmvvm.util

import com.fhz.loginmvvm.callback.LiveDataCallAdapterFactory
import kotlinx.coroutines.GlobalScope
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory

/**
 * 时间:2023/3/24
 * @author Mr.Feng
 * 简述: 网络 工具类
 */
object RetrofitManager {
    private lateinit var retrofit: Retrofit

    fun create(): Retrofit{
        retrofit = Retrofit.Builder()
                .baseUrl(Cons.HOST)
                .client(OkHttpClient.Builder()
                    .addInterceptor(HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
                    .build())
                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(LiveDataCallAdapterFactory())// callback -> livedata
                .build()
        return retrofit
    }
}